import {TableConstants} from 'ebom/constant/Constants.js'
import {PartUtils} from "ebom/part/PartUtils.js";
import {DrawingUtils} from "ebom/drawing/DrawingUtils.js";

/**
 * 版本管理工具类
 * @type {{}}
 */
export const VersionControlHelper = {


    updatePartIteration: function (partIterationId) {
        let oldPartIteration = informat.table.queryById(TableConstants.partIteration, partIterationId);
        //零件主对象id
        let partMasterId = oldPartIteration.primaryObject;
        //图纸版次id
        let drawingIterationId = oldPartIteration.drawingIterationId;

        let iteration = parseInt(oldPartIteration.iteration) + 1;

        // 1.新建零件版次记录
        let newPartIterationId = PartUtils.createPartIteration(partMasterId, oldPartIteration.phase, iteration, true);

        // 2.新建零件版次记录
        let drawingInfo = DrawingUtils.createDrawing(partMasterId, newPartIterationId);

        // 3. 添加关联列表
        informat.table.addRelation(TableConstants.partMasterTable, 'iterationList', partMasterId, newPartIterationId);

        // 4.更新记录
        informat.table.update(TableConstants.partIteration, {
            'id': partIterationId,
            'isLatestIteration': false,
        });

        // 4.更新记录
        informat.table.update(TableConstants.partMasterTable, {
            'id': partMasterId,
            'iterationId': newPartIterationId,
        });

        // 4.更新记录
        informat.table.update(TableConstants.partIterationTable, {
            'id': newPartIterationId,
            'drawingIterationId': drawingInfo.iterationId,
        });

    }


};